import request from '@/utils/request'

/**
 * 支付费率通道初始化
 * @param {Number} id 代理商id
 */
export function init() {
  return request({
    url: '/get_pay_configure',
    method: 'GET'
  })
}

/**
 * 费率提交
 * @param {object} official 提交参数
 * @param {object} wsChannel 提交参数
 * @param {object} fuChannel 提交参数
 * @param {object} leChannel 提交参数
 * @param {object} xdlChannel 提交参数
 */
export function sub(official, wsChannel, fuChannel, leChannel, xdlChannel) {
  const data = {
    rates: {
      wx: {
        normal: official.p_wx_rate,
        green: official.l_wx_rate,
        charity: official.g_wx_rate
      },
      ali: {
        normal: official.p_ali_rate,
        blue: official.l_ali_rate,
        charity: official.g_ali_rate
      },
      ws: {
        wx: {
          normal: wsChannel.p_wx_rate
        },
        ali: {
          normal: wsChannel.p_ali_rate,
          blue: wsChannel.l_ali_rate
        }
      },
      fumin: {
        wx: {
          normal: fuChannel.p_wx_rate,
          green: fuChannel.l_wx_rate
        },
        ali: {
          normal: fuChannel.p_ali_rate,
          blue: fuChannel.l_ali_rate
        }
      },
      lepos_swipe: {
        debit: {
          d1: {
            rate: leChannel.pos_d1_j_rate,
            ceiling: leChannel.pos_d1_j_f
          },
          d0: {
            rate: leChannel.pos_d0_j_rate
          }
        },
        credit: {
          d1: {
            rate: leChannel.pos_d1_d_rate
          },
          d0: {
            rate: leChannel.pos_d0_d_rate
          }
        },
        ovsea: {
          d1: {
            rate: leChannel.pos_d1_w_rate
          },
          d0: {
            rate: leChannel.pos_d0_w_rate
          }
        }
      },
      lepos_unipay: {
        debit: {
          d1: {
            greater: {
              rate: leChannel.yl_d1_j_b1000_rate,
              ceiling: leChannel.yl_d1_j_b1000_f
            },
            less: {
              rate: leChannel.yl_d1_j_s1000_rate
            }
          },
          d0: {
            greater: {
              rate: leChannel.yl_d0_j_b1000_rate
            },
            less: {
              rate: leChannel.yl_d0_j_s1000_rate
            }
          }
        },
        credit: {
          d1: {
            less: {
              rate: leChannel.yl_d1_d_s1000_rate
            },
            greater: {
              rate: leChannel.yl_d1_d_b1000_rate
            }
          },
          d0: {
            less: {
              rate: leChannel.yl_d0_d_s1000_rate
            },
            greater: {
              rate: leChannel.yl_d0_d_b1000_rate
            }
          }
        }
      },
      lepos_mob: {
        d1: {
          rate: leChannel.s_d1_rate
        },
        d0: {
          rate: leChannel.s_d0_rate
        }
      },
      starpos_swipe: {
        debit: {
          t1: {
            ceiling: xdlChannel.pos_t1_j_b1000_f,
            rate: xdlChannel.pos_t1_j_b1000_rate
          }
        },
        credit: {
          t1: {
            rate: xdlChannel.pos_t1_d_rate
          }
        }
      },
      starpos_unipay: {
        debit: {
          t1: {
            less: {
              rate: xdlChannel.yl_t1_j_s1000_rate
            },
            greater: {
              rate: xdlChannel.yl_t1_j_b1000_rate,
              ceiling: xdlChannel.yl_t1_j_b1000_f
            }
          }
        },
        credit: {
          t1: {
            less: {
              rate: xdlChannel.yl_t1_d_s1000_rate
            },
            greater: {
              rate: xdlChannel.yl_t1_d_b1000_rate
            }
          }
        }
      },
      starpos_mob: {
        t1: {
          rate: xdlChannel.s_t1_rate
        }
      }
    }
  }
  return request({
    url: '/edit_pay_configure',
    method: 'POST',
    data
  })
}

/**
 * 微信通道配置
 */
export function wechat() {
  return request({
    url: '/wechatAdd',
    method: 'GET'
  })
}

/**
 * 支付宝通道配置
 * @param {Number} id 代理商id
 */
export function zfbInit(id) {
  return request({
    url: '/zfb',
    method: 'GET',
    params: { id }
  })
}

/**
 * 网商银行通道配置
 * @param {Number} id 代理商id
 */
export function wsInit(id) {
  return request({
    url: '/ws',
    method: 'GET',
    params: { id }
  })
}

/**
 * 平安银行通道配置
 * @param {Number} id 代理商id
 */
export function paInit(id) {
  return request({
    url: '/pa',
    method: 'GET',
    params: { id }
  })
}

/**
 * 新大陆支付通道配置
 */
export function channelStarposSetting() {
  return request({
    url: '/starpos',
    method: 'GET'
  })
}

/**
 * 乐刷通道初始化
 */
export function channelLeInit() {
  return request({
    url: '/lepos',
    method: 'GET'
  })
}

/**
 * 乐刷通道初始化
 */
export function channelFuInit() {
  return request({
    url: '/fumin',
    method: 'GET'
  })
}

/**
 * 微信通道配置
 * @param {Object} date 提交参数
 */
export function wechatAdd(date) {
  const data = {
    appid: date.appid,
    secret: date.secret,
    merchant_id: date.merchant_id,
    notify_url: date.notify_url,
    key: date.key,
    apiclient_cert: date.apiclient_cert,
    apiclient_key: date.apiclient_key
  }
  return request({
    url: '/wechatAdd',
    method: 'POST',
    data
  })
}

/**
 * 支付宝通道配置
 * @param {Object} date 提交参数
 */
export function zfbAdd(date) {
  const data = {
    appid: date.appid,
    pid: date.pid,
    gateway: date.gateway,
    address: date.address,
    shop_url: date.shop_url,
    private_key: date.private_key,
    public_key: date.public_key
  }
  return request({
    url: '/zfb',
    method: 'POST',
    data
  })
}

/**
 * 网商银行通道配置
 * @param {Object} date 提交参数
 */
export function wsAdd(date) {
  const data = {
    isv: date.isv,
    appid: date.appid,
    wx_appid: date.wx_appid,
    secret: date.secret,
    apiclient_cert: date.apiclient_cert,
    apiclient_key: date.apiclient_key
  }
  return request({
    url: '/ws',
    method: 'POST',
    data
  })
}
/**
 * 平安银行通道配置
 * @param {Object} date 提交参数
 */
export function paAdd(date) {
  const data = {
    appid: date.appid,
    wechatapp_id: date.wechatapp_id,
    secret: date.secret,
    private_key: date.private_key,
    public_key: date.public_key
  }
  return request({
    url: '/pa',
    method: 'POST',
    data
  })
}

/**
 * 新大陆通道配置提交
 * @param {Object} date 提交参数
 */
export function channelStarposSetUpdate(date) {
  const data = {
    term_no: date.term_no,
    org_no: date.org_no,
    enter_key: date.enter_key,
    pay_key: date.pay_key
  }
  return request({
    url: '/starposupdate',
    method: 'POST',
    data
  })
}

/**
 * 乐刷通道配置提交
 * @param {Object} date 提交参数
 */
export function channelLeUpdate(date) {
  const data = {
    org_no: date.org_no,
    token_key: date.token_key,
    notify_key: date.notify_key
  }
  return request({
    url: '/leposupdate',
    method: 'POST',
    data
  })
}

/**
 * 富民通道配置提交
 * @param {Object} date 提交参数
 */
export function channelFuUpdate(date) {
  const data = {
    org_no: date.org_no,
    token_key: date.token_key,
    pay_public_key: date.pay_public_key,
    public_key: date.public_key,
    special_org_no: date.special_org_no,
    special_token_key: date.special_token_key
  }
  return request({
    url: '/fuminupdate',
    method: 'POST',
    data
  })
}

/**
 * 服务商信息配置
 * @param {Number} id 登录者id
 * @param {*} date 填写参数
 */
export function agentInfo(id, date) {
  const data = {
    id,
    company_name: date.name,
    company_short_name: date.store,
    company_logo: date.img
  }
  return request({
    url: '/editLogo',
    method: 'POST',
    data
  })
}

/**
 * 服务商公司信息配置查询
 * @param {Number} id 登陆id
 */
export function agentInfoInit(id) {
  return request({
    url: '/queryLogo',
    method: 'GET',
    params: { id }
  })
}

/**
 * 微信公众号消息模板配置
 * @param {Number} id 登陆id
 * @param {Object} date 配置参数
 */
export function wechatConfigSub(id, date) {
  const data = {
    token: date.token,
    id,
    encoding_aes_key: date.encoding_aes_key,
    wechat_name: date.name,
    wechat_qrcode: date.link,
    template_id: date.template_id
  }
  return request({
    url: '/wxmp',
    method: 'POST',
    data
  })
}

/**
 * 获取微信公众号配置
 */
export function wechatConfigGet() {
  return request({
    url: '/wxmp',
    method: 'GET'
  })
}

/**
 * 微信公众号菜单配置
 * @param {Number} id 登录者id
 * @param {Array} date 菜单参数
 */
export function wechatMenuSubmit(id, date) {
  const menus = date.length === 0 ? [] : { button: date }
  const data = {
    id,
    menus
  }
  return request({
    url: '/wxmp_menus',
    method: 'POST',
    data
  })
}

/**
 * 系统设置 守护进程初始化
 * @param {Number} id 登陆者id
 */
export function handleSystemInit(id) {
  return request({
    url: '/process_home',
    method: 'GET',
    params: { id }
  })
}

/**
 * 进程添加
 * @param {Object} date 添加参数
 */
export function processAdd(date) {
  const data = {
    title: date.name,
    desc: date.desc,
    command: date.cmd,
    interval: date.intval,
    arguments: date.arguments
  }
  return request({
    url: '/add_process',
    method: 'POST',
    data
  })
}

/**
 * 进程修改
 * @param {Number} id 进程id
 * @param {Object} date 添加参数
 */
export function processEdit(id, date) {
  const data = {
    id,
    title: date.name,
    desc: date.desc,
    command: date.cmd,
    interval: date.intval,
    arguments: date.arguments
  }
  return request({
    url: '/edit_process',
    method: 'POST',
    data
  })
}

/**
 * 进程修改获取
 * @param {Number} id 进程id
 */
export function processEditGet(id) {
  return request({
    url: '/edit_process',
    method: 'GET',
    params: { id }
  })
}

/**
 * 进程分页
 * @param {Number} page 进程分页
 */
export function processPage(page) {
  return request({
    url: '/process_home',
    method: 'GET',
    params: { page }
  })
}

/**
 * 删除进程
 * @param {Number} id 进程id
 */
export function processDelete(id) {
  return request({
    url: '/del_process',
    method: 'DELETE',
    params: { id }
  })
}

/**
 * 进程详情
 * @param {Number} id 进程id
 */
export function processInfo(id) {
  return request({
    url: '/see_process',
    method: 'GET',
    params: { id }
  })
}

/**
 * 更新进程状态
 * @param {Number} id 进程id
 * @param {Number} v 状态码
 */
export function processToggle(id, v) {
  return request({
    url: '/open_stop',
    method: 'PUT',
    params: { id, do: v }
  })
}

/**
 * 入驻协议管理初始化
 * @param {Number} id 登陆者id
 */
export function pactInit(id) {
  return request({
    url: '/queryAgreement',
    method: 'GET',
    params: { id }
  })
}

/**
 * 入驻协议管理分页
 * @param {Number} id 登陆者id
 */
export function pactCurrentPage(id, page) {
  return request({
    url: '/queryAgreement',
    method: 'GET',
    params: { id, page }
  })
}

/**
 * 入驻协议提交
 * @param {Object} id 代理商id
 * @param {Object} date 协议参数
 */
export function FileSubMit(user_id, date) {
  const data = {
    user_id,
    name: date.name,
    code: date.type,
    file: date.file
  }
  return request({
    url: '/addAgreement',
    method: 'POST',
    data
  })
}

/**
 * 入驻协议提交
 * @param {Object} id 协议id
 * @param {Object} date 协议参数
 */
export function fileEditSubmit(id, date) {
  const data = {
    id,
    name: date.name,
    code: date.type,
    file: date.file
  }
  return request({
    url: '/editAgreement',
    method: 'POST',
    data
  })
}

/**
 * 协议删除
 * @param {Number} id 协议id
 */
export function FileDelete(id) {
  return request({
    url: '/deleteAgreement',
    method: 'DELETE',
    params: { id }
  })
}

/**
 * 协议修改获取
 * @param {Number} id 协议id
 */
export function FileEdit(id) {
  return request({
    url: '/editAgreement',
    method: 'GET',
    params: { id }
  })
}

/**
 * 账号信息初始化
 */
export function accountInit() {
  return request({
    url: '/agent/agent/bank_info',
    method: 'GET'
  })
}

/**
 * 代理商修改获取短信
 */
export function GetSmsCode() {
  return request({
    url: '/agent/agent/get_sms_code',
    method: 'GET'
  })
}

/**
 * 修改密码提交
 * @param {Object} date 提交参数
 */
export function AccountEditPwd(mobile, date) {
  const data = {
    mobile,
    verify_code: date.code,
    new_password: date.password,
    confirm_password: date.vpassword
  }
  return request({
    url: '/agent/agent/edit_pwd',
    method: 'POST',
    data
  })
}

/**
 * 账号信息获取银行信息
 */
export function accountBankInit() {
  return request({
    url: '/agent/agent/query_bank_info',
    method: 'GET'
  })
}

/**
 * 账号信息提交
 * @param {Object} date 提交参数
 */
export function accountBankSubmit(date) {
  const data = {
    bank_account_no: date.bank_num,
    bank_accout_name: date.bank_name,
    deposit_bank: date.bank_code,
    sub_bank: date.bank_branch_code,
    photos: {
      posphoto: date.posphoto,
      sidephoto: date.sidephoto,
      handheld: date.handheld,
      bankphoto: date.bankphoto
    }
  }

  return request({
    url: '/agent/agent/edit_bank_account_info',
    method: 'POST',
    data
  })
}
